#!/sbin/openrc-run
supervisor=supervise-daemon

name="matrix-appservice-irc"
description="Daemon for matrix-appservice-irc, a Node.js IRC bridge for Matrix"

: ${command_user:="synapse:synapse"}
: ${config:="/etc/matrix-appservice-irc/config.yaml"}
: ${registration_file:="/etc/synapse/matrix-appservice-irc-registration.yaml"}
: ${port:=9999}

command="/usr/bin/matrix-appservice-irc"
command_args="-c $config -f $registration_file -p $port"
supervise_daemon_args="--chdir /var/lib/matrix-appservice-irc --stdout /var/log/matrix-appservice-irc.log --stderr /var/log/matrix-appservice-irc.log"

depends() {
	use logger
	need net
}

start_pre() {
	checkpath --owner $command_user --file /var/log/matrix-appservice-irc.log
	if [ ! -f $config ]; then
		eerror "Couldn't find config file!"
		return 1
	fi
	if [ ! -f $registration_file ]; then
		eerror "Couldn't find registration file!
		See https://github.com/matrix-org/matrix-appservice-irc#3-registration for how to generate one."
		return 1
	fi
}
